﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Validation;
using System.Linq;
using System.Text;
using GiveGraphModel;

namespace AModelTest
{
    class Program
    {
        static void Main()
        {
            /*/
            using (var ctx = new GiveGraphContext())
            {
                Database.SetInitializer<GiveGraphContext>(new DropCreateDatabaseAlways<GiveGraphContext>());
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Indiferente" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Outra" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Actor" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Administrativo" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Advogado" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Agente de Seguros" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Analista de Sistemas" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Analista Risco de Crédito" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Animador" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Arquitecto" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Arquivista" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Assistente Social" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Bibliotecário" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Biólogo" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Cabeleireiro" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Caixa" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Canalizador" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Carpinteiro" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Comercial" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Consultor" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Contabilista" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Cozinheiro" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Delegado de Informação Médica" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Dentista" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Desenhador" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Designer" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Dietista" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Economista" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Educador de Infância" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Electricista" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Empregado Mesa/Balcão" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Enfermeiro" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Engenheiro" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Escriturário" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Estafeta" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Estudante" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Farmacêutico" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Físico" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Fisioterapeuta" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Formador" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Fotógrafo" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Geógrafo" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Geólogo" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Gestor" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Guia" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Informático" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Jardineiro" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Jornalista" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Jurista" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Matemático" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Mecânico" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Médico" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Motorista" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Músico" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Pasteleiro" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Pintor" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Professor" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Psicólogo" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Químico" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "ROC-Revisor Oficial de Contas" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Secretária" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Segurança" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Serralheiro" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Sociólogo" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Técnico" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Técnico Superior" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Telefonista" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Terapeuta da Fala" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Tesoureiro" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "TOC - Técnico Oficial de Contas" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Tradutor" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Vendedor" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Veterinário" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Virologista" });
                ctx.ServicesCategories.Add(new ServiceCategory() { Description = "", Name = "Webdesigner" });
                ctx.SaveChanges();
            }
             //*/
            ;
            Database.SetInitializer<GiveGraphContext>(new SeedOnModelChangeModelChange());
            //Database.SetInitializer(new DropCreateDatabaseAlways<GiveGraphContext>());
            using (var ctx = new GiveGraphContext())
            {
                //foreach (var servicesCategory in ctx.ServicesCategories)
                //{
                //    Console.WriteLine(servicesCategory.Name);
                //}

                OrganizationCategory oc;
                ctx.OrganizationCategories.Add(oc = new OrganizationCategory {Name = "Crianças", Description = ""});

                OrganizationLocation loc = new OrganizationLocation{Description = "",Location = new Location{Address="Home", Country = "Portugal", ZipCode = "2000"}};


                ctx.Organizations.Add(new Organization
                                          {
                                              Name = "Organization X",
                                              FacebookToken = "sorcha08@hotmail.com",
                                              Categories = new List<OrganizationCategory> {oc},
                                              Locations = new List<OrganizationLocation> {loc}
                                          }
                    );

                ctx.SaveChanges();
            }
        }

        static void Main2(string[] args)
        {
            using (var ctx = new GiveGraphContext())
            {

                
                
                User usr = ctx.Users.Create();
                var entry = ctx.Entry(usr);

                var s = entry.State;
                usr.ZipCode = "";
                usr.Country = "";
                usr.FacebookToken = "fbtoken";
                ctx.Users.Add(usr);
                ctx.SaveChanges();
                foreach (var member in ctx.Members)
                {
                    Console.WriteLine("Member ID:" + member.MemberId);
                }
                var orgacat = new OrganizationCategory() { Name = "coisas", Description = "SomeCat" };
                ctx.OrganizationCategories.Add(orgacat);

   

                ctx.SaveChanges();


                Organization orga = ctx.Members.Create<Organization>();
                orga.Name = "Coisas";
                orga.FacebookToken = "";
                //ctx.Organizations.Attach(orga);
                
                //orga.Categories.Add(orgacat);
                //

                //usr.FollowingOrganizations.Add(orga);

                ctx.Organizations.Add(orga);
                ctx.SaveChanges();

                orga.Categories.Add(orgacat);
                ctx.SaveChanges();
                foreach (var member in ctx.Members)
                {
                    Console.WriteLine(member.MemberId);
                }
                foreach (var user in ctx.Users)
                {
                    Console.WriteLine(user.FacebookToken + "ID->" + user.MemberId);
                    foreach (var followingOrganization in user.FollowingOrganizations)
                    {
                        Console.WriteLine(followingOrganization.Name);
                    }
                }
                foreach (var organization in ctx.Organizations)
                {
                    foreach (var follower in organization.Followers)
                    {
                        Console.WriteLine(follower.FacebookToken);
                    }
                }


                return;
                Member a, b;
                //a = new User();
                //b = new User();

                ctx.Members.Add(a);
                ctx.Members.Add(b);
                ctx.SaveChanges();
                User x, y;
                x = ctx.Users.Create();
                var org = new Organization { Name = "AjudaAjuda" };
                /* var serviceRequest = new ServiceRequest() {Organization = org, Slots = 69};
                 var serviceResponse = new ServiceResponse()
                                           {Request = serviceRequest, Service = new Service() {Description = "xpto"}, User = x};
                 */
                //x.MemberId = ctx.Members.Create().MemberId;
                ctx.Users.Attach(x);
                x.Country = "PT";

                //ctx.Members.Add(x);

                ctx.Organizations.Add(org);
                //ctx.ServiceRequest.Add(serviceRequest);
                ctx.SaveChanges();
                y = ctx.Users.Create();
                //y.MemberId = ctx.Members.Create().MemberId;
                ctx.Users.Attach(y);
                y.Country = "EN";
                //ctx.Members.Add(y);

                //ctx.ServiceResponses.Add(serviceResponse);
                ctx.SaveChanges();

                foreach (var member in ctx.Users)
                {
                    member.FollowingOrganizations.Add(org);
                }

                var sr = ctx.ServiceResponses.First();
                



                foreach (var member in ctx.Users)
                {
                    Console.WriteLine(member.Country);
                }
                Console.WriteLine("SAI");
                Console.Read();
            }
        }
    }
}
